/*
 * @Author: 邵朋 
 * @Date: 2023-12-08 19:19:11
 * @LastEditors: 邵朋 
 * @LastEditTime: 2023-12-14 20:47:33
 * @FilePath: /YouDian/src/api/index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import Api from '../util/network/networkmanager';
import User from '../store/user'
import * as userutil from '../store/userutil'
import * as toast from '../util/toast/toast'

const api = new Api()


export function weixinUploadFile(file:any,callback:any)  {
    console.log('微信小程序开始上传图片了');
     // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
     wx.uploadFile({
      url: 'https://ydpt.wincrosoft.net/appapi/Upload/uploadfile', // 仅为示例，非真实的接口地址
      filePath: file.url,
      name: 'file',
      header:{
        'Content-Type': 'multipart/form-data',
      },
      formData: { method: 'POST' },
      success(res:any) {
        let result = JSON.parse(res.data)

        console.log('错误码:' + result.success)
        if(result.success){
          console.log('图片的上传地址:' + result.data.thumbpath)

          callback(result.data.thumbpath)


        }else{
            toast.infoToast(result.msg)
        }
      },
      fail(error:any){
        console.log('上传错误码:' + JSON.stringify(error))

        toast.infoToast(error.msg)
      }
    });
  }

///微信授权code置换openid的接口
 export function wxCodeChangeOpenIdRequest(data:any){
    return  api.get({
        path:'/sns/jscode2session',
        url:'https://api.weixin.qq.com',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}


     ///登录
 export function loginRequest(data:any){
    return  api.get({
        path:'/appletapi/Applet/AppletLogin',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}

   ///更新用户昵称
 export function updateUserNicknameRequest(data:any){
    return  api.post({
        path:'/appapi/User/updatenickname2',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}


   ///更新用户姓名
   export function updateUserRealnameRequest(data:any){
    return  api.post({
        path:'/appapi/User/updaterealname2',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}

  ///更新用户手机号
  export function updateUserMobileRequest(data:any){
    return  api.post({
        path:'/appapi/User/updateuserphone',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}



   ///更新用户头像
   export function updateUserHeadpicRequest(data:any){
    return  api.post({
        path:'/appapi/User/updatehead_portrait',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}

  ///查询用户信息
  export function queryUserinfoRequest(data:any){
    return  api.post({
        path:'/appapi/User/userinfo',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}





 ///查询设备信息
 export function queryEquipmentRequest(data:any){
    return  api.post({
        path:'/appapi/User/query_devicebycode',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}


 ///绑定新的设备信息
 export function addNewEquipmentRequest(data:any){
    return  api.post({
        path:'/appapi/Device/add_devicenew',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}

 ///删除绑定的设备信息
 export function deleteEquipmentRequest(data:any){
    return  api.post({
        path:'/appapi/Device/relieve_device',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}

 ///查询我的设备信息
 export function queryMyEquipmentListRequest(data:any){
    return  api.post({
        path:'/appapi/Device/get_mydevices',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}

 ///查询设备是否可以上传保养提示
 export function queryEquipmentCanSendMaintainTipsRequest(data:any){
    return  api.post({
        path:'/appapi/Device/issend_maintain_tip',
        queryData:data,
        contentType:'JSON',
        isShowHUD:false,
        isShowSuccessMsg:false,
        isShowErrorMsg:false
    })
}

 ///发送设备机油保养提示
 export function sendMaintainTipRequest(data:any){
    return  api.post({
        path:'/appapi/Device/send_maintain_tip',
        queryData:data,
        contentType:'JSON',
        isShowHUD:false,
        isShowSuccessMsg:false,
        isShowErrorMsg:false
    })
}


 ///获取最新一条未读消息
 export function queryNewUnreadMsgRequest(data:any){
    return  api.post({
        path:'/appapi/User/Get_NoReadMessages',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}

 ///获取最新一条机油保养信息
 export function queryNewMaintainTipRequest(data:any){
    return  api.post({
        path:'/appapi/Device/get_newest_maintain_tip',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}

 ///发送验证码 
 export function sendSMSCodeRequest(data:any){
    return  api.post({
        path:'/appapi/Device/sendsms',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}

 ///验证激活区域
 export function checkIsInActiveArea(data:any){
    return  api.post({
        path:'/appapi/Device/check_actcity',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}

 ///查询是否已激活
 export function checkDeviceIsActived(data:any){
    return  api.post({
        path:'/appapi/User/query_devicebyid',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}

 ///设备激活
 export function activeEquipmentReq (data:any){
    return  api.post({
        path:'/appapi/Device/act_device',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}

 ///更新设备开关机状态
 export function updateDevicePowerStatusReq (data:any){
    return  api.post({
        path:'/appapi/Device/update_devicepowerstatus',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}

 ///获取保养类型
 export function getMaintainTypeListReq (data:any){
    return  api.post({
        path:'/appapi/Device/get_maintaintype',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}


 ///增加保养记录
 export function addDeviceReq (data:any){
    console.log('新增保养入参:'+JSON.stringify(data))
    return  api.post({
        path:'/appapi/Device/add_maintain_record2',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}

///获取历史保养记录
export function getMaintainRecordListReq (data:any){
    return  api.post({
        path:'/appapi/Device/get_maintain_records',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}

///新增故障记录
export function addFaultRecordReq (data:any){
    return  api.post({
        path:'/appapi/Device/add_fault_record',
        queryData:data,
        contentType:'JSON',
        isShowHUD:false,
        isShowSuccessMsg:false,
        isShowErrorMsg:false
    })
}

///获取保养记录详情
export function getMaintainRecordDetailReq (data:any){
    return  api.post({
        path:'/appapi/Device/get_record_detail',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}

///获取设备控制版本
export function getControllerVersionReq  (data:any){
    return  api.post({
        path:'/appapi/Device/get_controllerr_version',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}

///上报电压实时信息
export function reportVoltageinfoReq  (data:any){
    return  api.post({
        path:'/appapi/Report/report_voltageinfo',
        queryData:data,
        contentType:'JSON',
        isShowHUD:false,
        isShowSuccessMsg:false,
        isShowErrorMsg:false
    })
}

///上报功率实时信息
export function reportPowerinfoReq  (data:any){
    return  api.post({
        path:'/appapi/Report/report_powerinfo',
        queryData:data,
        contentType:'JSON',
        isShowHUD:false,
        isShowSuccessMsg:false,
        isShowErrorMsg:false
    })
}

///上报速率实时信息
export function reportSpeedinfoReq  (data:any){
    return  api.post({
        path:'/appapi/Report/report_speedinfo',
        queryData:data,
        contentType:'JSON',
        isShowHUD:false,
        isShowSuccessMsg:false,
        isShowErrorMsg:false
    })
}

///上报油门实时信息 
export function reportGasinfoReq  (data:any){
    return  api.post({
        path:'/appapi/Report/report_gasinfo',
        queryData:data,
        contentType:'JSON',
        isShowHUD:false,
        isShowSuccessMsg:false,
        isShowErrorMsg:false
    })
}

///上报油门实时信息 
export function reportRuntimeReq  (data:any){
    return  api.post({
        path:'/appapi/Report/report_cumulativedata2',
        queryData:data,
        contentType:'JSON',
        isShowHUD:false,
        isShowSuccessMsg:false,
        isShowErrorMsg:false
    })
}

///上报设备连接蓝牙信息
export function reportBlueToothinfo (data:any){
    return  api.post({
        path:'/appapi/Report/report_bluetooth',
        queryData:data,
        contentType:'JSON',
        isShowHUD:false,
        isShowSuccessMsg:false,
        isShowErrorMsg:false
    })
}

///根据蓝牙协议唯一id查设备id 
export function queryDeviceIdByBlueToothIdReq (data:any){
    return  api.post({
        path:'/appapi/User/query_bluetoothbyid',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:false
    })
}


///绑定蓝牙协议唯一id  
export function bindBlueToothByUnionIdReq (data:any){
    return  api.post({
        path:'/appapi/Device/Bind_BluetoothId',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:false
    })
}

///根据设备id查蓝牙协议唯一id
export function queryBlueToothIdByDeviceIdReq (data:any){
    return  api.post({
        path:'/appapi/User/query_devicebluetoothid',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:false
    })
}

///消息列表
export function msgListReq (data:any){
    return  api.post({
        path:'/appapi/User/get_usermessages',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}

///已读一条消息
export function readOneMsgReq (data:any){
    return  api.post({
        path:'/appapi/User/update_message_readed',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}

///已读全部消息
export function readAllMsgReq (data:any){
    return  api.post({
        path:'/appapi/User/read_all_message',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}


///删除一条消息
export function deleteOneMsgReq (data:any){
    return  api.post({
        path:'/appapi/User/del_message',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}
///获取培训视频列表
export function videoListReq (data:any){
    return  api.post({
        path:'/appapi/User/gettrainvideos',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}

///获取是否展示培训视频
export function videoEnranceCongifReq (data:any){
    return  api.get({
        path:'/manageapi/Manage/getSysConfig',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}


///记录旧蓝牙的激活时间
export function recordOldBluetoothActiveTimeReq (data:any){
    return  api.post({
        path:'/appapi/Device/act_olddevice',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}

///记录旧蓝牙的激活时间
export function aboutusReq (data:any){
    return  api.post({
        path:'/appapi/User/get_aboutus',
        queryData:data,
        contentType:'JSON',
        isShowHUD:true,
        isShowSuccessMsg:false,
        isShowErrorMsg:true
    })
}
